package com.example.designpatternproject.builder;


import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.Toast;

import com.example.base.BaseActivity;
import com.example.designpatternproject.R;
import com.example.designpatternproject.databinding.ActivityBuilderBinding;


/**
 * @ClassName: BuilderActivity
 * @Author: 史大拿
 * @CreateDate: 10/18/22$ 1:59 PM$
 * TODO 工厂模式
 */
public class BuilderActivity extends BaseActivity<ActivityBuilderBinding> {

    @Override
    public void initView(Bundle savedInstanceState) {

        new ImplDefaultNavigationBar.Builder(this, R.layout.builder_default_item, binding.toolbarView1)
                .setText(R.id.tv_msg, "测试是否改变")
//                .setVisibility(R.id.tv_msg, View.GONE)
                .setOnClickListener(R.id.tv_msg, v -> {
                    Toast.makeText(getApplicationContext(), "文字点击了", Toast.LENGTH_SHORT).show();
                })
                .setOnClickListener(R.id.image, v -> {
                    Toast.makeText(getApplicationContext(), "返回点击了", Toast.LENGTH_SHORT).show();
                })
                .builder();


        new ImplEditNavigationBar.Builder(this, R.layout.builder_edit_item, binding.toolbarView2)
                .setOnTextChangedListener(R.id.edit_msg, new EditTextWatcher())// 监听搜索事件

                .setText(R.id.edit_msg, "S12英雄联盟冠军是哪一只?") // 修改文字

                // 搜索框点击监听
                .setOnClickListener(R.id.img_search, v -> Toast.makeText(getApplicationContext(), "可能是RNG", Toast.LENGTH_SHORT).show())
                .builder();


    }

    private static class EditTextWatcher implements TextWatcher {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            Log.i("szjTextChanged", "s:" + s);
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    }
}
